# 编写函数ping，用于测试远程主机的连通性（ping）
# 执行ping命令，3次，输出到黑洞设备
# 如果通显示：xxxx：up，否则显示:  xxxx:down
import subprocess
def ping(host):
    # 执行系统命令
    result = subprocess.run(f'ping -c 3 {host} &> /dev/null', shell=True)
    # print(result)
    if result.returncode == 0:
        print(f'{host}:up')
    else:
        print(f'{host}:down')

if __name__ == '__main__':
    # ping('192.168.88.130')
    # ping('127.0.0.1')
    hosts = ['www.jd.com', '192.168.88.100', 'www.google.com',
             'www.meituan.com', '127.0.0.1', 'www.mi.com']
    for item in hosts:
        ping(item)

